package com.wxy.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
import java.util.UUID;

/**
 * @author 47868
 */
@Configuration
public class RabbitMqSendMessage {
    private static final Logger log = LoggerFactory.getLogger(RabbitMqSendMessage.class);
    private final RabbitTemplate rabbitTemplate;
    @Autowired
    public RabbitMqSendMessage(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }
    public void sendMessage(String exchange, String routingKey, String sendMessage) {
        CorrelationData correlationData = new CorrelationData("1234567890");

        // 发送消息
        rabbitTemplate.convertAndSend(exchange, routingKey, sendMessage,message -> {
            message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
            return message;
        },correlationData);
        log.debug("消息已发送，ID: {}", correlationData.getId());
    }
}
